#include "../include/cc_object.h"

cc_uint32_t idcode = 0;

void free_object(cc_object_t o) {
	free(o);
	o = NULL;
}

void cc_printf_object_info(cc_object_t object) {
	if (object->type == CC_Class_Vector) {
		printf("Vector:");
	}
	if (object->type == CC_Class_Queue) {
		printf("Queue:");
	}
	if (object->type == CC_Class_Stack) {
		printf("Stack:");
	}
	if (object->type == CC_Class_List) {
		printf("List:");
	}
	if (object->type == CC_Class_DQueue) {
		printf("DQueue:");
	}
	if (object->type == CC_Class_LStack) {
		printf("DStack:");
	}
	printf("%s:%d\n", object->name,object->id);
}

cc_object_t CC_New_Object(cc_uint8_t* name, cc_uint8_t type)
{
	cc_object_t object = new(cc_object);
	if (object == NULL)
	{
		return CC_FALSE;
	}
	if (name == NULL) {
		strcpy_s(object->name, CC_NAME_MAX, "DEFAULT");
	}
	else {
		if (strlen(name) > CC_NAME_MAX) {
			strcpy_s(object->name, CC_NAME_MAX, "Rebuild to Long Name");
		}
		else {
			strcpy_s(object->name, CC_NAME_MAX, name);
		}
		
	}
	object->id = idcode++;
	object->type = type;
	object->free = free_object;
#if (DEBUG_TO_STRING_CLASS_INFO == 1)
	object->toString = cc_printf_object_info;
#endif
	return object;
}





